package com.lcf.system.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.GoodsCartDTO;
import com.lcf.system.query.GoodsCartPageQuery;
import com.lcf.system.service.GoodsCartService;
import com.lcf.system.vo.GoodsCartVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 购物车(GoodsCart)表控制层
 *
 * @author lcf
 * @since 2025-05-02 11:55:00
 */
@Tag(name = "购物车")
@RestController
@RequestMapping("goodsCart")
public class GoodsCartController {
    @Resource
    private GoodsCartService goodsCartService;

    /**
     * 新增购物车
     */
    @Operation(summary = "新增购物车")
    @SaCheckPermission("goodsCart:add")
    @PostMapping("add")
    public boolean addGoodsCart(@RequestBody @Validated GoodsCartDTO dto) {
        return goodsCartService.addGoodsCart(dto);
    }

    /**
     * 删除购物车
     */
    @Operation(summary = "删除购物车")
    @SaCheckPermission("goodsCart:delete")
    @DeleteMapping("{id}")
    public boolean deleteGoodsCart(@PathVariable @Schema(description = "购物车ID") long id) {
        return goodsCartService.deleteGoodsCart(id);
    }

    /**
     * 修改购物车
     */
    @Operation(summary = "修改购物车")
    @SaCheckPermission("goodsCart:update")
    @PatchMapping("{id}")
    public boolean updateGoodsCart(@PathVariable @Schema(description = "购物车ID") long id,
                                   @RequestBody @Validated GoodsCartDTO dto) {
        return goodsCartService.updateGoodsCart(id, dto);
    }

    /**
     * 查询购物车
     */
    @Operation(summary = "查询购物车")
    @SaCheckPermission("goodsCart:query")
    @GetMapping("{id}")
    public GoodsCartVO getGoodsCart(@PathVariable @Schema(description = "购物车ID") long id) {
        return goodsCartService.getGoodsCart(id);
    }

    /**
     * 查询购物车列表
     */
    @Operation(summary = "查询购物车列表")
    @SaCheckPermission("goodsCart:query")
    @GetMapping("page")
    public PageVO<GoodsCartVO> getGoodsCartList(GoodsCartPageQuery query) {
        return goodsCartService.getGoodsCartList(query);
    }
}

